<template>
 <view class="context">
 	<view class="head">
 		<view class="head-left">
 			<image src="/static/order-list.png"></image>
 		</view>
 		<view class="head-right">
 			<view class="head-right-top">等待付款</view>
 			<view class="head-right-bottom">请尽快付款完成交易，否则订单将自动取消</view>
 		</view>
 	</view>
 	<view class="box">
 		<view class="box-info">
 			<text>订单信息</text>
 			<view class="box-info-right">IPFS有效存储算力</view>
 		</view>
 		<view class="box-info">
 			<text>订单编号</text>
 			<view class="box-info-right">IPFS有效存储算力</view>
 		</view>
 		<view class="box-info">
 			<text>下单时间</text>
 			<view class="box-info-right">IPFS有效存储算力</view>
 		</view>
 		<view class="box-info">
 			<text>购买数量</text>
 			<view class="box-info-right">IPFS有效存储算力</view>
 		</view>
 		<view class="box-info">
 			<text>算力总量</text>
 			<view class="box-info-right">IPFS有效存储算力</view>
 		</view>
 		<view class="box-info">
 			<text>上架时间</text>
 			<view class="box-info-right">3天</view>
 		</view>
 		<view class="box-info">
 			<text>单价</text>
 			<view class="box-info-right">2880</view>
 		</view>
 	</view>
 	<u-line color="#f5f5f5" margin="40rpx 0 0 0"></u-line>
 	<view class="fix-footer">
 		<view class="footer">
 			<view class="footer-left">
 				<view>总金额：<text class="tag">￥2880</text></view>
 			</view>
 			<view class="footer-right">
 				<button class="submit" @click="submit">提交订单</button>
 				<payKeyboard v-if="showKeyBoard" title="Mi安全键盘" @success="enterSuccess" @close="close">
 				</payKeyboard>
 			</view>
 		</view>
 	</view>
 </view>
</template>

<script>
  import payKeyboard from './mi-payKeyboard/mi-payKeyboard.vue'
import { mapActions, mapGetters, mapState } from "vuex";
export default {
  data() {
    return {
      isLoading: false,
      detail: null,
      number: 1,
      agreement: false,
      showpay: false,
      goodid: null,
      mfc: null,
      coin: null,
      showKeyBoard: false
    };
  },
  components: { payKeyboard },
  methods: {
    ...mapActions("user", ["loadUser"]),
    ...mapActions("mf/shop", ["getGoodInfo", "buyGood", "mfcPrice"]),
    ...mapActions("mf/my", ["coinBalance"]),
    submit() {
    	this.showKeyBoard = true
    },
    // 输入正确的回调
    enterSuccess(password) {
    	console.log(password) // 输入的密码
    	this.showKeyBoard = false
    },
    // 点击[取消] 关闭输入框 的回调
    close() {
    	this.showKeyBoard = false
    },
    // 增加数量
    addNumber() {
      if (this.number >= this.detail.stock) {
        this.makeToast({ title: "剩余库存不足" });
        return;
      }
      this.number += 1;
    },
    // 减少数量
    minusNumber() {
      if (this.number <= 1) {
        return;
      }
      this.number -= 1;
    },
    // 是否同意协议
    checkedChange() {
      this.agreement = !this.agreement;
    },
    // 打开密码
    openPass() {
      // console.log("pass");
      if (!this.agreement) {
        this.makeToast({ title: this.$t("agreement") });
        return;
      }
      this.showpay = true;
    },
    // 关闭密码
    togglePayPassword() {
      this.showpay = false;
    },
    // 密码输入完成
    async payPasswordDone(data) {
      this.togglePayPassword();
      let detail = await this.buyGood({
        id: this.goodid,
        number: this.number,
        pay_password: data.password,
      });
      console.log(detail);
      // this.makeToast({ title: this.$t("mf.c2c.buy_success") });
      this.handleNavTo({
        url:
          "/pages/mf/shop/buySuccess?ordersn=" +
          detail.order_sn +
          "&price=" +
          detail.price_total_m,
      });
    },
  },
  computed: {
    ...mapState("user", ["user"]),
    ...mapGetters("system", ["locale"]),
    getPower() {
      return this.number * this.detail.power;
    },
    totalPrice() {
      return this.MFCAmont * this.number;
    },
    MFCAmont() {
      return parseFloat(this.detail.price / this.mfc.USDT).toFixed(2);
    },
  },
  async onLoad(option) {
    this.goodid = option.id;
    this.isLoading = true;
    await this.loadUser();
    this.detail = await this.getGoodInfo({ id: option.id });
    this.mfc = await this.mfcPrice();
    this.coin = await this.coinBalance({ symbol: "M" });
    this.isLoading = false;
  },
};
</script>

<style scoped lang="scss">
	.head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 160rpx;
		color: #fff;
		background: #2A96EE;
		padding: 20rpx;

		.head-left {
			image {
				width: 107rpx;
				height: 104rpx;
			}
		}

		.head-right {
			text-align: right;
      padding-right: 20rpx;
		}
	}

	.box {
		padding: 20rpx;

		.box-info {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;

			.box-info-right {
				text-align: right;
			}
		}
	}

	.fix-footer {
		position: fixed;
		width: 100%;
		bottom: 0rpx;
	}

	.footer {
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 2rpx solid #f5f5f5;
		padding: 20rpx;

		.footer-left {
			color: #999999;
			font-size: 24rpx;

			.tag {
				font-size: 36rpx;
				color: #E23E28;
			}
		}

		.footer-right {
			.submit {
				width: 240rpx;
				height: 68rpx;
				font-size: 32rpx;
				line-height: 68rpx;
				background: #2A96EE;
				border-radius: 34rpx;
				color: #fff;
			}
		}
	}
</style>
